import 'package:flutter/services.dart';
import 'package:kmxy_base/util/event.dart';
import 'package:package_info_plus/package_info_plus.dart';

import 'base_event_const.dart';

class BaseGlobal {
  /// 当前页面名称
  static String currentPageName = '';

  static getClipboardData({String noRunPage = ''}) async {
    // 获取剪切板里的内容跳转页面
    ClipboardData? data = await Clipboard.getData(Clipboard.kTextPlain);
    String clipboardDataText = data?.text ?? '';
    PackageInfo packageInfo = await PackageInfo.fromPlatform();
    if (clipboardDataText.contains(packageInfo.packageName) &&
        noRunPage != currentPageName) {
      Clipboard.setData(const ClipboardData(text: ''));
      Future.delayed(const Duration(milliseconds: 500), () {
        Event.eventBus.fire(Event(EVENT_ClipboardData, clipboardDataText));
      });
    }
  }

  /// base_main 是否初始化完成
  static bool isMainInitData = false;
}
